<template>
	<view class="page-container">
		<!-- 顶部操作栏 -->
		<view class="page-header">
			<view class="header-left">
				<text class="page-title">请假申请管理</text>
				<text class="page-subtitle">管理所有员工请假申请</text>
			</view>
			<view class="header-right">
				<button class="btn btn-primary" @click="handleAdd">
					<text class="icon">+</text> 新增申请
				</button>
			</view>
		</view>

		<!-- 搜索和筛选栏 -->
		<view class="filter-section">
			<view class="search-box">
				<input 
					v-model="searchParams.keyword"
					type="text"
					placeholder="搜索申请人姓名..."
					class="search-input"
					@confirm="handleSearch"
				/>
				<button class="btn-search" @click="handleSearch">搜索</button>
				<button class="btn-reset" @click="handleReset">重置</button>
			</view>
			
			<!-- 批量操作按钮 -->
			<view v-if="selectedIds.length > 0" class="batch-actions">
				<text class="batch-count">已选中 {{ selectedIds.length }} 项</text>
				<button class="btn btn-danger btn-small" @click="handleBatchDelete">删除选中</button>
				<button class="btn btn-default btn-small" @click="handleCancelSelect">取消选择</button>
			</view>
		</view>

		<!-- 数据表格 -->
		<view class="table-wrapper">
			<view v-if="loading" class="loading-state">
				<text class="loading-text">加载中...</text>
			</view>

			<view v-else-if="dataList.length === 0" class="empty-state">
				<text class="empty-icon">📭</text>
				<text class="empty-text">暂无请假申请</text>
				<button class="btn btn-primary" @click="handleAdd">新增申请</button>
			</view>

			<view v-else class="table-container">
				<!-- 表头 -->
				<view class="table-header">
					<view class="table-cell checkbox-cell">
						<checkbox-group @change="handleSelectAll">
							<label>
								<checkbox :checked="isSelectAll" value="all" />
							</label>
						</checkbox-group>
					</view>
					<view class="table-cell col-name">申请人</view>
					<view class="table-cell col-role">职务</view>
					<view class="table-cell col-type">请假类型</view>
					<view class="table-cell col-period">请假时段</view>
					<view class="table-cell col-days">天数</view>
					<view class="table-cell col-status">状态</view>
					<view class="table-cell col-approver">审批人</view>
					<view class="table-cell col-actions">操作</view>
				</view>

				<!-- 表行 -->
				<view v-for="item in dataList" :key="item._id" class="table-row"
					:class="{ selected: selectedIds.includes(item._id) }">
					<view class="table-cell checkbox-cell" @click.stop>
						<checkbox-group @change="(e) => handleSelectItem(item._id, e)">
							<label>
								<checkbox :checked="selectedIds.includes(item._id)" :value="item._id" />
							</label>
						</checkbox-group>
					</view>
					<view class="table-cell col-name clickable" @click="handleView(item._id)">
						<text class="cell-text">{{ item.requester_name || '未知' }}</text>
					</view>
					<view class="table-cell col-role clickable" @click="handleView(item._id)">
						<text class="cell-text">{{ getHighestRoleText(item) }}</text>
					</view>
					<view class="table-cell col-type clickable" @click="handleView(item._id)">
						<text class="cell-text">{{ getLeaveTypeText(item.leave_type) }}</text>
					</view>
					<view class="table-cell col-period clickable" @click="handleView(item._id)">
						<text class="cell-text">{{ item.start_date }} ~ {{ item.end_date }}</text>
					</view>
					<view class="table-cell col-days clickable" @click="handleView(item._id)">
						<text class="cell-text">{{ item.duration_days }}天</text>
					</view>
					<view class="table-cell col-status" @click.stop>
						<!-- 待审批状态：显示两个按钮 -->
						<view v-if="item.status === 1" class="approval-buttons">
							<button class="approval-btn approve-btn" @click="handleApprove(item)">批准</button>
							<button class="approval-btn reject-btn" @click="handleReject(item)">拒绝</button>
						</view>
						<!-- 已批准/已拒绝状态：普通显示 -->
						<text 
							v-else
							class="status-badge"
							:class="'status-' + getStatusClass(item.status)"
						>
							{{ getStatusText(item.status) }}
						</text>
					</view>
					<view class="table-cell col-approver clickable" @click="handleView(item._id)">
						<text class="cell-text">{{ item.approver_name || '-' }}</text>
					</view>
					<view class="table-cell col-actions" @click.stop>
						<button 
							v-if="item.status === 1 || item.status === 3"
							class="action-btn edit-btn" 
							@click="handleEdit(item._id)"
						>编辑</button>
						<button class="action-btn delete-btn" @click="handleDelete(item._id)">删除</button>
					</view>
				</view>
			</view>
		</view>

		<!-- 分页 -->
		<view v-if="dataList.length > 0" class="pagination-section">
			<view class="pagination-info">
				<text>共 {{ total }} 条数据，第 {{ currentPage }} / {{ totalPages }} 页</text>
				<view class="page-size-selector">
					<text class="selector-label">每页显示</text>
					<picker 
						mode="selector" 
						:range="pageSizeOptions" 
						:value="pageSizeIndex"
						@change="handlePageSizeChange"
						class="selector-picker"
					>
						<view class="selector-input">{{ pageSize }} 条</view>
					</picker>
				</view>
			</view>
			<view class="pagination-controls">
				<button 
					:disabled="currentPage === 1"
					class="btn btn-default btn-small"
					@click="handlePreviousPage"
				>上一页</button>
				<button 
					:disabled="currentPage === totalPages"
					class="btn btn-default btn-small"
					@click="handleNextPage"
				>下一页</button>
			</view>
		</view>
	</view>
</template>

<script setup>

import { ref, computed, onMounted } from 'vue'
import { store as uniIdPagesStore } from '@/uni_modules/uni-id-pages/common/store.js'

// 数据状态
const dataList = ref([])
const loading = ref(false)
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(20)

// 审批弹窗状态
const showApprovalModal = ref(false)
const currentApprovalItem = ref(null)
const approvalAction = ref('approve') // 'approve' or 'reject'
const rejectionReason = ref('')

// 分页选项
const pageSizeOptions = ['10 条', '20 条', '50 条', '100 条']
const pageSizeValues = [10, 20, 50, 100]
const pageSizeIndex = computed(() => pageSizeValues.indexOf(pageSize.value))

// 搜索和过滤
const searchParams = ref({
	keyword: ''
})

// 选择状态
const selectedIds = ref([])

const totalPages = computed(() => Math.ceil(total.value / pageSize.value))
const isSelectAll = computed(() => dataList.value.length > 0 && dataList.value.length === selectedIds.value.length)

// 初始化
onMounted(() => {
	loadData()
})

// 加载数据
async function loadData() {
	loading.value = true
	try {
		const dhLeaveRequests = uniCloud.importObject('dh-leave_requests')
		const skip = (currentPage.value - 1) * pageSize.value
		const query = {}
		
		const result = await dhLeaveRequests.listLeaveRequests(query, skip, pageSize.value)
		
		if (result.code === 200) {
			dataList.value = result.data || []
			total.value = result.count || 0
			selectedIds.value = []
		} else {
			uni.showToast({ title: result.message || '加载失败', icon: 'error' })
		}
	} catch (error) {
		console.error('加载数据失败:', error)
		uni.showToast({ title: '加载数据失败', icon: 'error' })
	} finally {
		loading.value = false
	}
}

// 获取最高权重的角色文本
function getHighestRoleText(item) {
	// 角色权重定义（数值越大权重越高）
	const roleWeights = {
		'admin': 100,
		'manager': 90,
		'director': 80,
		'vice_director': 70,
		'head_nurse': 60,
		'finance': 50,
		'administrative': 40,
		'purchaser': 35,
		'doctor': 30,
		'nurse': 20,
		'staff': 10,
		'patient': 0
	}
	
	const roleNames = {
		'admin': '超级管理员',
		'manager': '管理员',
		'director': '院长',
		'vice_director': '副院长',
		'head_nurse': '护士长',
		'finance': '财务',
		'administrative': '行政',
		'purchaser': '采购员',
		'doctor': '医生',
		'nurse': '护士',
		'staff': '员工',
		'patient': '患者'
	}
	
	// 优先使用完整角色数组
	let roles = []
	if (item.requester_roles && Array.isArray(item.requester_roles)) {
		roles = item.requester_roles
	} else if (item.requester_role) {
		roles = Array.isArray(item.requester_role) ? item.requester_role : [item.requester_role]
	}
	
	if (roles.length === 0) {
		return item.requester_role_text || '-'
	}
	
	// 找出权重最高的角色
	let highestRole = roles[0]
	let highestWeight = roleWeights[highestRole] || 0
	
	for (const role of roles) {
		const weight = roleWeights[role] || 0
		if (weight > highestWeight) {
			highestWeight = weight
			highestRole = role
		}
	}
	
	return roleNames[highestRole] || highestRole
}

// 获取请假类型文本
function getLeaveTypeText(type) {
	const typeMap = {
		1: '病假',
		2: '年假',
		3: '事假',
		4: '其他'
	}
	return typeMap[type] || '未知'
}

// 获取状态文本
function getStatusText(status) {
	// 处理可能的字符串类型状态
	const numStatus = parseInt(status)
	
	const statusMap = {
		1: '待审批',
		2: '已批准',
		3: '已拒绝'
	}
	
	// 兼容字符串类型的状态值（如 "approved", "rejected", "pending"）
	const stringStatusMap = {
		'pending': '待审批',
		'approved': '已批准',
		'rejected': '已拒绝'
	}
	
	// 优先使用数字映射，然后尝试字符串映射
	if (statusMap[numStatus]) {
		return statusMap[numStatus]
	} else if (typeof status === 'string' && stringStatusMap[status.toLowerCase()]) {
		return stringStatusMap[status.toLowerCase()]
	} else if (statusMap[status]) {
		return statusMap[status]
	}
	
	// 调试日志
	console.log('未知状态值:', status, '类型:', typeof status, '转换后:', numStatus)
	return '未知'
}

// 获取状态样式类
function getStatusClass(status) {
	// 处理可能的字符串类型状态
	const numStatus = parseInt(status)
	
	const classMap = {
		1: 'pending',
		2: 'approved',
		3: 'rejected'
	}
	
	// 兼容字符串类型的状态值
	const stringClassMap = {
		'pending': 'pending',
		'approved': 'approved',
		'rejected': 'rejected'
	}
	
	// 优先使用数字映射，然后尝试字符串映射
	if (classMap[numStatus]) {
		return classMap[numStatus]
	} else if (typeof status === 'string' && stringClassMap[status.toLowerCase()]) {
		return stringClassMap[status.toLowerCase()]
	} else if (classMap[status]) {
		return classMap[status]
	}
	
	return 'pending'
}

// 搜索
function handleSearch() {
	currentPage.value = 1
	loadData()
}

// 重置搜索
function handleReset() {
	searchParams.value.keyword = ''
	currentPage.value = 1
	loadData()
}

// 选择/取消选择单项
function handleSelectItem(id, e) {
	const values = e.detail.value
	if (values.includes(id)) {
		if (!selectedIds.value.includes(id)) {
			selectedIds.value.push(id)
		}
	} else {
		const index = selectedIds.value.indexOf(id)
		if (index > -1) {
			selectedIds.value.splice(index, 1)
		}
	}
}

// 全选/取消全选
function handleSelectAll(e) {
	const values = e.detail.value
	if (values.includes('all')) {
		selectedIds.value = dataList.value.map(item => item._id)
	} else {
		selectedIds.value = []
	}
}

// 取消选择
function handleCancelSelect() {
	selectedIds.value = []
}

// 新增
function handleAdd() {
	uni.navigateTo({
		url: '/pages/business/leave_requests/add'
	})
}

// 查看详情
function handleView(id) {
	uni.navigateTo({
		url: `/pages/business/leave_requests/detail?id=${id}`
	})
}

// 编辑（仅待审批和已拒绝状态可编辑）
function handleEdit(id) {
	uni.navigateTo({
		url: `/pages/business/leave_requests/edit?id=${id}`
	})
}

// 批准请假申请
function handleApprove(item) {
	currentApprovalItem.value = item
	
	uni.showModal({
		title: '批准请假申请',
		content: `申请人：${item.requester_name || '未知'}\n请假类型：${getLeaveTypeText(item.leave_type)}\n请假时段：${item.start_date} ~ ${item.end_date}\n请假天数：${item.duration_days}天\n请假原因：${item.reason || '无'}\n\n确定批准此请假申请吗？`,
		showCancel: true,
		cancelText: '取消',
		confirmText: '确定批准',
		confirmColor: '#007aff',
		success: (res) => {
			if (res.confirm) {
				executeApproval(item._id, 'approve', '')
			}
		}
	})
}

// 拒绝请假申请
function handleReject(item) {
	currentApprovalItem.value = item
	showRejectReasonDialog(item._id)
}

// 显示拒绝原因输入框
function showRejectReasonDialog(id) {
	uni.showModal({
		title: '拒绝原因',
		editable: true,
		placeholderText: '请输入拒绝原因',
		success: async (res) => {
			if (res.confirm) {
				const reason = (res.content || '').trim()
				if (!reason) {
					uni.showToast({ title: '请输入拒绝原因', icon: 'none' })
					// 重新显示输入框
					setTimeout(() => {
						showRejectReasonDialog(id)
					}, 1500)
					return
				}
				await executeApproval(id, 'reject', reason)
			}
		}
	})
}

// 执行审批操作
async function executeApproval(id, action, reason) {
	try {
		const dhLeaveRequests = uniCloud.importObject('dh-leave_requests')
		const userInfo = uniIdPagesStore.userInfo || {}
		const approverId = userInfo._id
		const approverName = userInfo.username || userInfo.nickname || '管理员'
		
		let result
		if (action === 'approve') {
			result = await dhLeaveRequests.approveLeaveRequest(id, approverId, approverName)
		} else {
			result = await dhLeaveRequests.rejectLeaveRequest(id, reason)
		}
		
		if (result.code === 200) {
			uni.showToast({ 
				title: action === 'approve' ? '批准成功' : '已拒绝', 
				icon: 'success' 
			})
			loadData()
		} else {
			uni.showToast({ title: result.message || '操作失败', icon: 'error' })
		}
	} catch (error) {
		console.error('审批失败:', error)
		uni.showToast({ title: '审批失败', icon: 'error' })
	}
}

// 删除单条
async function handleDelete(id) {
	const confirmed = await showConfirm('确认删除', '确定要删除此请假申请吗？')
	if (!confirmed) return

	try {
		const dhLeaveRequests = uniCloud.importObject('dh-leave_requests')
		const result = await dhLeaveRequests.deleteLeaveRequest(id)
		
		if (result.code === 200) {
			uni.showToast({ title: '删除成功', icon: 'success' })
			loadData()
		} else {
			uni.showToast({ title: result.message || '删除失败', icon: 'error' })
		}
	} catch (error) {
		console.error('删除失败:', error)
		uni.showToast({ title: '删除失败', icon: 'error' })
	}
}

// 批量删除
async function handleBatchDelete() {
	if (selectedIds.value.length === 0) {
		uni.showToast({ title: '请选择要删除的项', icon: 'warning' })
		return
	}

	const confirmed = await showConfirm('批量删除', `确定要删除选中的 ${selectedIds.value.length} 项吗？`)
	if (!confirmed) return

	try {
		const dhLeaveRequests = uniCloud.importObject('dh-leave_requests')
		const result = await dhLeaveRequests.batchDeleteLeaveRequests(selectedIds.value)
		
		if (result.code === 200) {
			uni.showToast({ title: '批量删除成功', icon: 'success' })
			selectedIds.value = []
			loadData()
		} else {
			uni.showToast({ title: result.message || '批量删除失败', icon: 'error' })
		}
	} catch (error) {
		console.error('批量删除失败:', error)
		uni.showToast({ title: '批量删除失败', icon: 'error' })
	}
}

// 分页
function handlePreviousPage() {
	if (currentPage.value > 1) {
		currentPage.value--
		loadData()
	}
}

function handleNextPage() {
	if (currentPage.value < totalPages.value) {
		currentPage.value++
		loadData()
	}
}

// 改变每页显示条数
function handlePageSizeChange(e) {
	const index = e.detail.value
	pageSize.value = pageSizeValues[index]
	currentPage.value = 1  // 重置到第一页
	loadData()
}

// 辅助函数
function showConfirm(title, content) {
	return new Promise((resolve) => {
		uni.showModal({
			title,
			content,
			confirmText: '确定',
			cancelText: '取消',
			success: (res) => {
				resolve(res.confirm)
			}
		})
	})
}
</script>

<style scoped lang="scss">
.page-container {
	padding: 20px;
	background-color: #f5f7fa;
	min-height: 100vh;
}

.page-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 24px;
	background: white;
	padding: 20px;
	border-radius: 8px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.header-left {
	display: flex;
	flex-direction: column;
}

.page-title {
	font-size: 20px;
	font-weight: 600;
	color: #1f2937;
	margin-bottom: 4px;
}

.page-subtitle {
	font-size: 12px;
	color: #6b7280;
}

.header-right {
	display: flex;
	gap: 10px;
}

.btn {
	padding: 6px 14px;
	border-radius: 6px;
	border: none;
	cursor: pointer;
	font-size: 14px;
	font-weight: 500;
	transition: all 0.3s ease;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 34px;
	box-sizing: border-box;

	&:disabled {
		opacity: 0.5;
		cursor: not-allowed;
	}

	&.btn-primary {
		background-color: #3b82f6;
		color: white;

		&:active {
			background-color: #2563eb;
		}
	}

	&.btn-default {
		background-color: #e5e7eb;
		color: #374151;

		&:active {
			background-color: #d1d5db;
		}
	}

	&.btn-danger {
		background-color: #ef4444;
		color: white;

		&:active {
			background-color: #dc2626;
		}
	}

	&.btn-small {
		padding: 6px 12px;
		font-size: 12px;
	}
}

.icon {
	font-size: 16px;
}

.filter-section {
	display: flex;
	flex-direction: column;
	gap: 16px;
	margin-bottom: 20px;
}

.search-box {
	display: flex;
	gap: 8px;
	background: white;
	padding: 12px;
	border-radius: 8px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.search-input {
	flex: 1;
	padding: 8px 12px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	font-size: 14px;
	height: 38px;
	box-sizing: border-box;

	&:focus {
		outline: none;
		border-color: #3b82f6;
		box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
	}
}

.btn-search {
	padding: 8px 16px;
	background-color: #3b82f6;
	color: white;
	border: 1px solid #3b82f6;
	border-radius: 6px;
	cursor: pointer;
	font-size: 14px;
	font-weight: 500;
	height: 38px;
	box-sizing: border-box;
	display: flex;
	align-items: center;

	&:active {
		background-color: #2563eb;
	}
}

.btn-reset {
	padding: 8px 16px;
	background-color: #e5e7eb;
	color: #374151;
	border: 1px solid #e5e7eb;
	border-radius: 6px;
	cursor: pointer;
	font-size: 14px;
	font-weight: 500;
	height: 38px;
	box-sizing: border-box;
	display: flex;
	align-items: center;

	&:active {
		background-color: #d1d5db;
	}
}

.batch-actions {
	display: flex;
	align-items: center;
	gap: 12px;
	background: white;
	padding: 12px;
	border-radius: 8px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.batch-count {
	font-size: 14px;
	color: #6b7280;
	font-weight: 500;
}

.table-wrapper {
	background: white;
	border-radius: 8px;
	overflow-x: auto;
	overflow-y: visible;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
	margin-bottom: 20px;
	
	/* 确保滚动条可见 */
	&::-webkit-scrollbar {
		height: 8px;
	}
	
	&::-webkit-scrollbar-track {
		background: #f1f1f1;
		border-radius: 4px;
	}
	
	&::-webkit-scrollbar-thumb {
		background: #c1c1c1;
		border-radius: 4px;
		
		&:hover {
			background: #a8a8a8;
		}
	}
}

.loading-state,
.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px 20px;
}

.loading-text {
	font-size: 14px;
	color: #6b7280;
}

.empty-icon {
	font-size: 48px;
	margin-bottom: 12px;
}

.empty-text {
	font-size: 14px;
	color: #6b7280;
	margin-bottom: 16px;
}

.table-container {
	display: inline-block;
	min-width: 100%;
	width: max-content;
}

.table-header {
	display: grid;
	grid-template-columns: 40px 100px 80px 90px 180px 70px 90px 100px 120px;
	gap: 12px;
	padding: 12px 16px;
	background-color: #f9fafb;
	border-bottom: 1px solid #e5e7eb;
	font-size: 12px;
	font-weight: 600;
	color: #6b7280;
	text-transform: uppercase;
	letter-spacing: 0.5px;

	.table-cell {
		justify-content: center;
	}
}

.table-row {
	display: grid;
	grid-template-columns: 40px 100px 80px 90px 180px 70px 90px 100px 120px;
	gap: 12px;
	padding: 12px 16px;
	border-bottom: 1px solid #e5e7eb;
	align-items: center;
	transition: background-color 0.2s ease, border-left 0.2s ease;

	&:hover {
		background-color: #f9fafb;
	}

	&:last-child {
		border-bottom: none;
	}

	&.selected {
		background-color: #eff6ff;
		border-left: 3px solid #3b82f6;
		padding-left: 13px;
	}

	.table-cell {
		justify-content: center;
	}

	.col-actions {
		justify-content: flex-start;
		padding-left: 8px;
	}
}

.table-cell {
	display: flex;
	align-items: center;
}

.checkbox-cell {
	justify-content: center;

	checkbox-group {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	label {
		display: flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
	}

	checkbox {
		transform: scale(1.1);
	}
}

.cell-text {
	font-size: 14px;
	color: #1f2937;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.status-badge {
	display: inline-block;
	padding: 4px 12px;
	border-radius: 4px;
	font-size: 12px;
	font-weight: 600;
	border: none;
	cursor: default;

	&.status-pending {
		background-color: #fef3c7;
		color: #92400e;
		
		&.clickable-badge {
			cursor: pointer;
			transition: all 0.3s ease;
			
			&:hover {
				background-color: #fde68a;
			}
			
			&:active {
				background-color: #fcd34d;
				transform: scale(0.98);
			}
		}
	}

	&.status-approved {
		background-color: #d1fae5;
		color: #065f46;
	}

	&.status-rejected {
		background-color: #fee2e2;
		color: #991b1b;
	}
}

.approval-buttons {
	display: flex;
	gap: 4px;
	justify-content: center;
	align-items: center;
}

.approval-btn {
	padding: 4px 12px;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-size: 12px;
	font-weight: 600;
	transition: all 0.3s ease;
	white-space: nowrap;
	height: 26px;
	display: flex;
	align-items: center;
	box-sizing: border-box;
	
	&.approve-btn {
		background-color: #d1fae5;
		color: #065f46;
		
		&:hover {
			background-color: #a7f3d0;
		}
		
		&:active {
			background-color: #6ee7b7;
			transform: scale(0.95);
		}
	}
	
	&.reject-btn {
		background-color: #fee2e2;
		color: #991b1b;
		
		&:hover {
			background-color: #fecaca;
		}
		
		&:active {
			background-color: #fca5a5;
			transform: scale(0.95);
		}
	}
}

.col-actions {
	display: flex;
	gap: 6px;
	justify-content: flex-start;
}

.clickable {
	cursor: pointer;
	transition: background-color 0.2s ease;

	&:hover {
		background-color: #f9fafb;
	}
}

.action-btn {
	padding: 4px 10px;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-size: 12px;
	font-weight: 500;
	transition: all 0.3s ease;
	white-space: nowrap;
	height: 26px;
	display: flex;
	align-items: center;
	box-sizing: border-box;
	min-width: 50px;
	justify-content: center;

	&.approve-btn {
		background-color: #dbeafe;
		color: #1e40af;

		&:hover {
			background-color: #bfdbfe;
		}

		&:active {
			background-color: #93c5fd;
		}
	}

	&.edit-btn {
		background-color: #fef3c7;
		color: #92400e;

		&:hover {
			background-color: #fde68a;
		}

		&:active {
			background-color: #fcd34d;
		}
	}

	&.delete-btn {
		background-color: #fee2e2;
		color: #991b1b;

		&:hover {
			background-color: #fecaca;
		}

		&:active {
			background-color: #fca5a5;
		}
	}
}

.pagination-section {
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: white;
	padding: 16px;
	border-radius: 8px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.pagination-info {
	display: flex;
	align-items: center;
	gap: 16px;
	font-size: 12px;
	color: #6b7280;
}

.page-size-selector {
	display: flex;
	align-items: center;
	gap: 8px;
}

.selector-label {
	font-size: 12px;
	color: #6b7280;
}

.selector-picker {
	flex-shrink: 0;
}

.selector-input {
	padding: 4px 8px;
	border: 1px solid #d1d5db;
	border-radius: 4px;
	font-size: 12px;
	color: #374151;
	background-color: white;
	cursor: pointer;
	min-width: 70px;
	text-align: center;
}

.pagination-controls {
	display: flex;
	gap: 8px;
}

/* 移动端响应式设计 */
@media (max-width: 768px) {
	.page-container {
		padding: 12px;
	}

	.page-header {
		flex-direction: row;
		align-items: center;
		gap: 8px;
		padding: 12px;
	}

	.header-left {
		flex: 1;
		min-width: 0;
	}

	.header-right {
		flex-shrink: 0;
	}

	.page-title {
		font-size: 16px;
	}

	.page-subtitle {
		font-size: 11px;
		line-height: 1.4;
	}

	.btn {
		padding: 6px 12px;
		font-size: 13px;
		height: auto;
	}

	.search-box {
		flex-wrap: wrap;
	}

	.search-input {
		width: 100%;
		flex: 1 1 100%;
		margin-bottom: 8px;
	}

	.btn-search,
	.btn-reset {
		flex: 1;
		justify-content: center;
	}

	.batch-actions {
		flex-wrap: wrap;
	}

	/* 表格容器添加横向滚动 */
	.table-wrapper {
		overflow-x: auto;
	}

	.table-container {
		min-width: 1000px; /* 设置最小宽度，允许横向滚动 */
	}

	/* 分页区域 */
	.pagination-section {
		flex-direction: column;
		gap: 12px;
		align-items: flex-start;
	}

	.pagination-info {
		flex-direction: column;
		align-items: flex-start;
		gap: 8px;
		width: 100%;
	}

	.page-size-selector {
		width: 100%;
		justify-content: space-between;
	}

	.selector-picker {
		flex: 0 0 auto;
	}

	.selector-input {
		min-width: 80px;
	}

	.pagination-controls {
		width: 100%;
		justify-content: space-between;
	}

	.btn.btn-small {
		flex: 1;
	}
}
</style>
